* ======================================
* --------- PrWin Illustration ---------
* ======================================


	* Prediction model on non-anonymized data 
	use $dta_ext/PredictionModel_candid.dta , clear

	replace party_loc = "r" if party_loc == "rødt"
	
	gen party = ""
	replace party = "Labour Party" if party_loc == "a"
	replace party = "Progress Party" if party_loc == "frp"
	replace party = "Conservative Party" if party_loc == "h"
	replace party = "Christian Dem. Party" if party_loc == "krf"
	replace party = "Centre Party" if party_loc == "sp"
	replace party = "Red Party" if party_loc == "r"
	replace party = "Socialist Left Party" if party_loc == "sv"
	replace party = "Liberal Party" if party_loc == "v"
	replace party = "Green Party" if party_loc == "mdg"
	
	rename electedpr_leaveout Polit_prWin	
	drop rank_loc
	rename rank_loc_orig rank_loc

	
* Make scatter plots
* ==================
	
	foreach p in r sv a sp mdg krf v h frp{
		
		preserve 
		
		keep if party_loc=="`p'" & knr_loc==1804 & year==2019
		local party = party[1]
		
		twoway ///
		(scatter Polit_prWin rank_loc if preadvantage_loc==1 & ///
			elected_loc==1, msymbol(T) mcolor(gs2) msize(2.5pt)) ///
		(scatter Polit_prWin rank_loc if preadvantage_loc==1 & ///
			elected_loc==0, msymbol(Th) mcolor(cranberry) msize(2.5pt)) ///
		(scatter Polit_prWin rank_loc if preadvantage_loc==0 & ///
			elected_loc==1, msymbol(S) mcolor(gs2) msize(2.5pt)) ///
		(scatter Polit_prWin rank_loc if preadvantage_loc==0 & ///
			elected_loc==0, msymbol(Sh) mcolor(cranberry) msize(2.5pt)) ///
		, xtitle(List position, size(vsmall)) ylabel(, grid angle(0)) ///
		ytitle("Probability", size(vsmall)) ///
		xlabel(1 5(5)45, labsize(vsmall)) ylabel(0(0.2)1.0 , labsize(vsmall)) ///
		title(`party', size(small)) xscale(reverse) ///
		legend(order(2 "Head start 1 Elected 0" 1 "Head start 1 Elected 1" ///
			4 "Head start 0 Elected 0" 3 "Head start 0 Elected 1") ///
			cols(2) pos(6) size(vsmall)) ///
		scheme(plotplain) name(`p', replace)
		 
		restore
		
	}
	
	grc1leg r sv a sp mdg krf v h frp, cols(3) scheme(plotplain) name(prWin, replace)
	graph display prWin, ysize(5)
	graph export $figs/PrWinIllustration.pdf, replace
	